<?php
class View_Message_List extends View_Message
{
	/**
	 *	...
	 *	@access		public
	 *	@return		string
	 */
	public function buildContent()
	{
		$words		= $this->words['message']['list'];
		$current	= $this->auth->getCurrentUser();

		$ui	= array(
			'in_list'		=> $this->renderMessageList(
				Logic_Message::getMessagesReceivedBy( $current )
			),
			'out_list'		=> $this->renderMessageList(
				Logic_Message::getMessagesSentBy( $current )
			),
			'caption_in'	=> $this->html->TableCaption( $words['captionInbox'] ),
			'caption_out'	=> $this->html->TableCaption( $words['captionOutbox'] ),
			'colgroup'		=> $this->html->ColumnGroup( "25", "100", "" ),
			'heading'		=> $words['heading'],
			'buttonNew'		=> $this->html->LinkButton(
				self::getUrl( array( 'action' => 'add' ) ),
				$words['buttonNew'],
				'but add'
			),
		);
		return $this->loadTemplate( 'message.list', $ui );
	}

	private function renderMessageList( $messages )
	{
		$list	= array();
		foreach( $messages as $message )
		{
			$data	= array(
				'status'	=> $this->getStatusIcon( $message['status'] ),
				'user'		=> Logic_User::getUserData( $message['source'] ),
				'link'		=> $this->html->Link(
					self::getUrl( array( 'messageId' => $message['messageId'] ) ),
					$message['subject']
				),
			);
			$list[]	= $this->loadTemplate( 'message.listitem', $data );
		}
		return implode( "", $list );
	}
}
?>